IF EXISTS (SELECT * FROM sysobjects WHERE name = 'GetMachineNameForMachineId' AND type IN ('FN','IF','TF'))
     DROP FUNCTION dbo.GetMachineNameForMachineId
GO

CREATE FUNCTION dbo.GetMachineNameForMachineId
     ( @MachineId int )
RETURNS varchar(255)
AS
/*
 *
 * GetMachineNameForMachineId
 *
 * Purpose:      
 *
 * Inputs:       
 *
 * Assumes:      
 *
 * Effects:      
 *
 * Returns:      
 *
 * Calling
 * Application:  
 *
 * Note(s):      
 *
 * Author(s):    NOVA Concepts Ltd.
 *
 * Change Log:   Initial Release, 10/12/2011, 1.00.0000
 *
 */
BEGIN
     DECLARE @ReturnValue varchar(255)

     SELECT @ReturnValue = COALESCE( FQMachineName, MachineName )
     FROM   dbo.Machine 
     WHERE  MachineId = @MachineId

     RETURN @ReturnValue
END
GO
